<template>
    <div>
      <van-nav-bar
        title="我的收货地址"
        left-text="关闭"
        right-text=""
        left-arrow
        @click-left="onClickLeft"
        @click-right="onClickLeft"
      />
      <van-address-list
        v-model="chosenAddressId"
        :list="list"
        :disabled-list="disabledList"
        disabled-text="以下地址超出配送范围"
        default-tag-text="默认"
        @add="onAdd"
        @edit="onEdit"
      />
    </div>
</template>

<script>
  import axios from 'axios'
    export default {
        name: "user_address",
      data() {
        return {
          id:sessionStorage.getItem("id"),
          chosenAddressId: '1',
          list: [],
          disabledList: [
            {
              id: '3',
              name: '王五',
              tel: '1320000000',
              address: '浙江省杭州市滨江区江南大道 15 号',
            },
          ],
        };
      },
      methods: {
        onClickLeft(){
          this.$router.go(-1);
        },
        onAdd() {
          this.$router.push("/addAddress")
        },
        onEdit(item, index) {
          console.log(index);
          console.log(item);
          this.$router.push({path:"/addAddress",query:{
            item:item
            }})
        },
        findAddress(){
          axios.post("api/user/findaddress",{uid:this.id}).then(res=>{
            if(res.data.code==200){
              this.list=res.data.data;
            }
          })
        }
      },
      mounted(){
          this.findAddress();
      }
    }
</script>

<style scoped>

</style>
